﻿#include "EditorAddComponentPropertyView.h"

#include "Widgets/Widget.h"
#include "Widgets/RectangleWidget.h"
#include "Widgets/TextWidget.h"
#include "Widgets/Mouse/MouseWidget.h"
#include "Widgets/Positioners/VerticalPositionerWidget.h"

#include "Framework/Editor.h"
#include "Theme/EditorTheme.h"

void REditorAddComponentPropertyView::BindViewModel(TSharedObjectPtr<REditorPropertyViewModel> InViewModel)
{
    Super::BindViewModel(InViewModel);
    AddComponentViewModel = InViewModel;
}

void REditorAddComponentPropertyView::CreateWidget(TSharedObjectPtr<RVerticalPositionerWidget> InPropertyList)
{
    auto Root=NewWidget<RWidget>(InPropertyList);
    Root->Anchor.HorizontalFill(InPropertyList);
    Root->Height=AddComponentViewModel->LineHeight;

    auto Background=NewWidget<RRectangleWidget>(Root);
    Background->Anchor.VerticalFill(Root);
    Background->Anchor.HorizontalCenterReference=Root;
    Background->Width=150;
    Background->Radius=4;

    auto Mouse=NewWidget<RMouseWidget>(Background);
    Mouse->Anchor.Fill(Background);
    RMouseWidgetWeakPtr MouseWeak=Mouse;
    Background->FillColor=[MouseWeak]()->SColor
    {
        return MouseWeak->IsHovered()
        ?REditor::Get()->CurrentTheme->HighlightColor_Hover
        :REditor::Get()->CurrentTheme->HighlightColor;
    };
    Mouse->OnClicked.BindLambda([this,MouseWeak](const SMouseButtonEvent&){
        AddComponentViewModel->OnAddComponentClicked(MouseWeak);
        return true;
    });

    auto Label=NewWidget<RTextWidget>(Background);
    Label->Anchor.Fill(Background);
    Label->Text=U"+ 添加组件";
    Label->VerticalAlignment=ETextVerticalAlignment::Center;
    Label->HorizontalAlignment=ETextHorizontalAlignment::Center;


}
